<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>骡窝窝系统管理平台</title>
    <#include "../common/header.ftl"/>
    <script type="text/javascript" src="/js/plugins/My97DatePicker/WdatePicker.js"></script>
</head>

<body>
<div class="container">
<#include "../common/top.ftl"/>
    <div class="row">
        <div class="col-sm-3">
		<#assign currentMenu = "hotel" />
        <#include "../common/menu.ftl" />
        </div>
        <div class="col-sm-9">
            <div class="page-header">
                <h3>酒店管理</h3>
            </div>
            <div class="row">
                <!-- 提交分页的表单 -->
                <form id="searchForm" class="form-inline" method="post" action="/hotel/list.do">
                    <input type="hidden" name="currentPage" id="currentPage" value="1"/>
                    <div class="form-group">
                        <label for="keyword">关键字:</label>
                        <input type="text" class="form-control" id="keyword" name="keyword"  placeholder="请输入标题">
                    </div>
                    <div class="form-group">
                        <label>状态</label>
                        <select id="auditState" class="form-control"  name="state">
                            <option value="-2">全部</option>
                            <option value="1">推荐</option>
                            <option value="0">正常</option>
                            <option value="-1">禁用</option>
                        </select>
                        <button id="query" type="button" class="btn btn-success"><i class="icon-search"></i>查询</button>
                        <a href="javascript:void(-1);" class="btn btn-success inputHotelBtn">
                            <span class="glyphicon glyphicon-plus"></span>添加酒店
                        </a>
                    </div>
                </form>
            </div>
            <script>
                $("#auditState").val("${(qo.type)!}");
                $("#keyword").val("${(qo.keyword)!}");
            </script>
            <div class="row">
                <table class="table">
                    <thead>
                    <tr>
                        <th>序号</th>
                        <th>酒店名称</th>
                        <th>酒店所属地区</th>
                        <th>封面</th>
                        <th>状态</th>
                        <th></th>
                    </tr>

                    </thead>
                    <tbody>
					<#list info.list as entity>
                    <tr>
                        <td>${entity_index +  1}</td>
                        <td>${entity.name!""}</td>
                        <td>${(entity.place.name)!""}</td>
                        <td><img src='${entity.coverUrl!}' width="100px"/></td>
                        <td>${entity.stateName!""}</td>
                        <td><a class="inputHotelBtn" data-json='${entity.json}'>修改</a></td>
                    </tr>
					</#list>
                    </tbody>
                </table>
                <#include "../common/page.ftl"/>
            </div>
        </div>
    </div>
</div>
<#--酒店编辑模态框-->
<div id="strategyModal" class="modal" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">编辑/增加</h4>
            </div>
            <div class="modal-body">
                <form id="strategyForm" class="form-horizontal" method="post" action="/hotel/saveOrUpdate.do" enctype="multipart/form-data" style="margin: -3px 118px">
                    <input id="strategyId" type="hidden" name="id" />
                    <input id="reset" type="reset" style="display: none"/>

                    <div class="form-group">
                        <label class="col-sm-4 control-label">酒店名称</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="name" placeholder="酒店名称">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">封面</label>
                        <div class="col-sm-6">
                            <img width="200px"/>
                            <input type="hidden" name="coverUrl">
                            <input type="file" class="form-control"  name="file" >
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-4 control-label">所属地区</label>
                        <div class="col-sm-6">
                            <select id="place" class="form-control"  name="place.id"></select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">状态</label>
                        <div class="col-sm-6">
                            <select id="auditState" class="form-control"  name="state">
                                <option value="1">推荐</option>
                                <option value="0">普通</option>
                                <option value="-1">禁用</option>
                            </select>
                        </div>

                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <a href="javascript:void(0);" class="btn btn-success" id="saveStrategyBtn" aria-hidden="true">保存</a>
                <a href="javascript:void(0);" class="btn" data-dismiss="modal" aria-hidden="true">关闭</a>
            </div>
        </div>
    </div>
</div>
<style>
    #strategyModal img {
        width: 100%;
    }
</style>
<script>
    $("#query").click(function () {
        $("#searchForm").submit();
    });

    //按钮绑定点击事件,触发模态框
    $(".inputHotelBtn").click(function () {
        var json = $(this).data("json");
        $.get("/region/allRegions.do",function (data) {
           // console.log("hhh"+data);
            var temp = "";
            $.each(data,function (index,ele) {
                temp += "<option value="+ele.id+">"+ele.name+"</option>"
            });
            $("#place").html(temp);

            //回显酒店所在地区
            $("#place").val(json.placeId);



        });

        if(json){
            console.log(json);
            $("#strategyForm input[name='id']").val(json.id);
            $("#strategyForm input[name='name']").val(json.name);
            $("#strategyForm img").attr("src",json.coverUrl);
            $("#strategyForm input[name='coverUrl']").val(json.coverUrl);
            //回显酒店所在地区
            $("#place").val(json.placeId);
            $("#strategyForm select[name='state']").val(json.state);

        }else{
            $("#reset").click();
        }

        $("#strategyModal").modal("show");
    });


    $("#saveStrategyBtn").click(function () {
        $("#strategyForm").submit();
    });

</script>
</body>
</html>